package com.luguotao.lease.web.admin.schedule;

import com.luguotao.lease.model.entity.LeaseAgreement;
import com.luguotao.lease.model.enums.LeaseStatus;
import com.luguotao.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTasks {
    @Autowired
    LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * * ")
    public void checkLeaseAgreeStatu(){

        //修改状态为已到期  条件:  lease_end_date z租约结束日期      小于 当前日期new Date()
        //                       租约状态是 2,5
        //修改 状态 status
        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>().lt(LeaseAgreement::getLeaseEndDate,new Date()).
                in(LeaseAgreement::getStatus,2,5).set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED));
    }
}
